/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.toools.gwt.wmc.client.application.gui;

import java.util.Collection;
import java.util.Vector;
import org.toools.gwt.widget.client.bc.BusinessObjectPanel;
import org.toools.gwt.widget.client.bc.StringAttribute;
import org.toools.gwt.wmc.jpa.Application;
import org.toools.gwt.wmc.jpa.CompanyPart;

/**
 *
 * @author manuel
 */
public class ApplicationPanel extends BusinessObjectPanel{

    StringAttribute content = null;

    Collection<CompanyPart> parents = new Vector<CompanyPart>();

    public ApplicationPanel(Object bp) {
        super(bp, 2);

        content = new StringAttribute("content", false);
        content.setMaxLength(50);

        this.add( content );

        recreateContent();
        preselect();
        validate();

        setStatus("* missing or invalid input");
    }

    public void addParent(CompanyPart parent) {
        this.parents.add(parent);
    }

    public void preselect() {
        if (getBusinessObject() != null) {
            Application a = (Application) getBusinessObject();
            content.setAttributeValue(a.getContent());
        } else {
            content.setAttributeValue("");
        }
    }

    public void map() {
        if (getBusinessObject() == null) {
            setBusinessObject(new Application());
        }
        Application a = (Application) getBusinessObject();
        a.setContent("" + content.getAttributeValue());
        if(parents.size() > 0) {
            a.setCompanyParts(parents);
        }
    }

}
